'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public Class OfflineMessageResponse
    Inherits MetaResponse

    Public Sub New()
        MyBase.New(MetaResponseType.OfflineMessageResponse)
    End Sub

    Public Overrides Function CalculateDataSize() As Integer
        'Return 2 + 4 + 2 + 2 + 4 + 6 + 1 + 1 + 2 + _MessageText.Length
        Throw New NotImplementedException
    End Function

    Private _SenderUin As Long
    Public Property SenderUin() As Long
        Get
            Return _SenderUin
        End Get
        Set(ByVal value As Long)
            _SenderUin = value
        End Set
    End Property

    Private _DateSent As DateTime
    Public Property DateSent() As DateTime
        Get
            Return _DateSent
        End Get
        Set(ByVal value As DateTime)
            _DateSent = value
        End Set
    End Property

    Private _MessageText As String
    Public Property MessageText() As String
        Get
            Return _MessageText
        End Get
        Set(ByVal value As String)
            _MessageText = value
        End Set
    End Property

    Private _MessageType As MessageType
    Public Property MessageType() As MessageType
        Get
            Return _MessageType
        End Get
        Set(ByVal value As MessageType)
            _MessageType = value
        End Set
    End Property

    Private _MessageFlags As MessageFlag
    Public Property MessageFlags() As MessageFlag
        Get
            Return _MessageFlags
        End Get
        Set(ByVal value As MessageFlag)
            _MessageFlags = value
        End Set
    End Property

    Public Overrides Sub Deserialize(ByVal data As System.Collections.Generic.List(Of Byte))
        MyBase.Deserialize(data)

        Dim index As Integer = MetaResponse.SizeFixPart

        _SenderUin = ByteConverter.ToUInt32LE(data.GetRange(index, 4))
        index += 4

        Dim year As Integer
        Dim month As Integer
        Dim day As Integer
        Dim hour As Integer
        Dim minute As Integer

        year = ByteConverter.ToUInt16LE(data.GetRange(index, 2))
        index += 2

        month = data(index)
        index += 1

        day = data(index)
        index += 1

        hour = data(index)
        index += 1

        minute = data(index)
        index += 1

        _DateSent = New Date(year, month, day, hour, minute, 0)

        _MessageType = DirectCast(data(index), DataTypes.MessageType)
        index += 1

        _MessageFlags = DirectCast(data(index), MessageFlag)
        index += 1

        _MessageText = ByteConverter.ToStringFromUInt16LEIndex(index, data)
        If _MessageText.EndsWith(Chr(0)) Then _MessageText = _MessageText.Substring(0, _MessageText.Length - 1)
    End Sub

    Public Overrides Function Serialize() As System.Collections.Generic.List(Of Byte)
        Throw New NotImplementedException
    End Function
End Class

Public Enum MessageType As Byte
    PlainTextMessage = &H1
    ChatRequestMessage = &H2
    FileRequestMessage = &H3
    URLMessage = &H4
    AuthorizationRequestMessage = &H6
    AuthorizationDeniedMessage = &H7
    AuthorizationGivenMessage = &H8
    MessageFromOSCARServer = &H9
    YouWereAddedMessage = &HC
    WebPagerMessage = &HD
    EmailExpressMessage = &HE
    ContactListMessage = &H13
    PluginMessage = &H1A
    AutoAwayMessage = &HE8
    AutoOccupiedMessage = &HE9
    AutoNotAvailableMessage = &HEA
    AutoDoNotDisturbMessage = &HEB
    AutoFreeForChatMessage = &HEC
End Enum

Public Enum MessageFlag As Byte
    NormalMessage = &H1
    AutoMessage = &H3
    MultipleRecipientsMessage = &H80
End Enum